<?php

namespace Api\Controller;

use Common\Controller\FuncController;

class UserBaseController extends FuncController
{
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 从token里拿到用户信息
     * @param $signature
     * @return array|mixed
     */
    public function getUserForSign($signature)
    {
        if(!$signature){
            return ['error'=>1,'msg'=>'非法访问'];
        }
        $signatureData = user_decrypt($signature);
        if(!$signatureData->user_id){
            return ['error'=>1,'msg'=>'token 错误'];
        }

        if($signatureData->exp < time()){
            return ['error'=>1,'msg'=>'token 过期'];
        }

        $userModel  = D('User');
        return ['error'=>0,'data'=>$userModel->find($signatureData->user_id)];
    }
}